package com.fcat.common.user.controller;

import com.alibaba.fastjson.JSONObject;
import com.fcat.springboot.mybatis.controller.TsuantoneBaseController;
import com.fcat.springboot.mybatis.util.JsonUtil;
import com.fcat.base.common.util.StrUtil;
import com.fcat.common.user.entity.Company;
import com.fcat.common.user.service.CompanyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("company")
public class CompanyController extends TsuantoneBaseController<CompanyService, Company, Integer> {

    @ApiOperation("注册单位")
    @PostMapping("/addCompany")
    public JSONObject addCompany(@RequestBody Company company) {
        return bsi.addCompany(company);
    }

    @ApiOperation("根据单位全称,纳税人识别号,单位类别查询单位信息")
    @GetMapping("/getByValue")
    public JSONObject getByValue(@RequestParam("name") String name, @RequestParam("taxpayerIdentificationNumber") String taxpayerIdentificationNumber) {
        if (StrUtil.isBlank(name)) return JsonUtil.getFailJsonObject("请先填写单位全称");
        if (StrUtil.isBlank(taxpayerIdentificationNumber)) return JsonUtil.getFailJsonObject("请先填写纳税人识别号");
        Company tmp = new Company();
        tmp.setName(name);
        tmp.setTaxpayerIdentificationNumber(taxpayerIdentificationNumber);
        Company company = bsi.selectOne(tmp);
        if (company == null) return JsonUtil.getFailJsonObject("单位不存在");
        return JsonUtil.getSuccessJsonObject(company);
    }


}